package com.ycy.chuwenuniapp.controller;

import com.ycy.chuwenuniapp.common.ResData;
import com.ycy.chuwenuniapp.dto.GoodsDetailDto;
import com.ycy.chuwenuniapp.dto.GoodsDto;
import com.ycy.chuwenuniapp.dto.GoodsOutboundDto;
import com.ycy.chuwenuniapp.dto.GoodsTypeDto;
import com.ycy.chuwenuniapp.service.GoodsService;
import com.ycy.chuwenuniapp.service.GoodsTypeService;
import com.ycy.chuwenuniapp.vo.GoodsDetailVo;
import com.ycy.chuwenuniapp.vo.GoodsTypeCountVo;
import com.ycy.chuwenuniapp.vo.GoodsTypeVo;
import com.ycy.chuwenuniapp.vo.GoodsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "商品管理")
@RequestMapping("/goods")
@RestController
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @PostMapping("/add")
    @ApiOperation("新增商品")
    public ResData<String> addGoods(@RequestBody GoodsDetailDto dto) {
        return goodsService.addGoods(dto, true);
    }

    @PostMapping("/update")
    @ApiOperation("修改商品")
    public ResData<String> updateGoods(@RequestBody GoodsDetailDto dto) {
        return goodsService.updateGoods(dto);
    }

    @GetMapping("/findEveryTypeGoodsCount")
    @ApiOperation("查询每类商品的数量")
    public ResData<ArrayList<GoodsTypeCountVo>> findEveryTypeGoodsCount() {
        return goodsService.findEveryTypeGoodsCount();
    }

    @GetMapping("/findAll")
    @ApiOperation("查询全部商品")
    public ResData<List<GoodsVo>> findAll(String typeId, String name) {
        return goodsService.findAll(typeId, name);
    }

    @GetMapping("/findOneDetail")
    @ApiOperation("查询单个商品详情")
    public ResData<GoodsDetailVo> findOneDetail(String goodsId,Boolean isOutbound) {
        return goodsService.findOneDetail(goodsId,isOutbound);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除单个商品")
    public ResData<Boolean> delete(String goodsId) {
        return goodsService.delete(goodsId);
    }

    @PostMapping("/outbound")
    @ApiOperation("商品出库")
    public ResData<Boolean> outbound(@RequestBody List<GoodsOutboundDto> dtoList) {
        return goodsService.outbound(dtoList);
    }

    @GetMapping("/findAllLackGoods")
    @ApiOperation("查询全部缺货商品")
    public ResData<List<GoodsVo>> findAllLackGoods(String typeId, String name) {
        return goodsService.findAllLackGoods(typeId, name);
    }

//    @GetMapping("/findAllLackGoods")
//    @ApiOperation("查询全部缺货商品")
//    public ResData<List<GoodsDetailVo>> findAllLackGoods(String typeId, String name) {
//        return goodsService.findAllLackGoods(typeId, name);
//    }
}
